package cn.com.eado.crm.m.repository

import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import cn.com.eado.crm.m.AppExecutors
import cn.com.eado.crm.m.net.MyRetrofit
import cn.com.eado.crm.model.NetworkBoundResource
import cn.com.eado.crm.model.Resource
import cn.com.eado.crm.model.net.ApiResponse

class LoginRepository {

    fun login(name: String, pwd: String, mac: String): LiveData<Resource<String>> {
        return object: NetworkBoundResource<String, String>(AppExecutors()){
            override fun shouldLoadFromDb(): Boolean = false

            override fun loadFromDb(): LiveData<String> = MediatorLiveData<String>()

            override fun createCall() = MediatorLiveData<ApiResponse<String>>()

            override fun saveCallResult(item: String) {}

            override fun shouldFetch(data: String?) = true

            override fun createCall2(): LiveData<ApiResponse<String>> = MyRetrofit.getInstance().api.userLogin(name, pwd/*, mac*/)
        }.asLiveData()
    }
}